package com.heima.article.listener;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.heima.article.entity.ApArticle;
import com.heima.article.service.IApArticleService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

/**
 * @Author WSJ
 * @Date 2022-03-17-17:26
 * @Version 1.0 （版本号）
 */
@Service
public class DownOrUpListener {
    @Autowired
    private IApArticleService apArticleService;

    @KafkaListener(topics = "${topic.downorup}")
    public void listen(ConsumerRecord<String, String> record) {
        String articleId = record.key();
        String enable = record.value();
        LambdaUpdateWrapper<ApArticle> query=new LambdaUpdateWrapper<>();
        query.eq(ApArticle::getId,articleId);
        query.set(ApArticle::getIsDown, "true".equals(enable) ? false : true);
        apArticleService.update(query);
    }
}
